<template>
	<view :style="{'height':windowHeight}">
		<clothes></clothes>
		<view class="login"
			style="background: url(https://public-1329395846.cos.ap-nanjing.myqcloud.com/images/login.png);background-size: 100% 100%;background-repeat: no-repeat;">
			<view style="height: 25%;"></view>
			<view class="login-box">
				<view class="login-box-one">欢迎注册/登录</view>
				<view class="login-box-ipone">
					<input maxlength="11" placeholder="请输入手机号" type="number" v-model="mobile" />
				</view>


				<view class="login-box-ipone1" style="margin-top: 30rpx;">
					<view class="login-code">
						<input maxlength="6" placeholder="请输入验证码" v-model="code" type="number" />
					</view>
					<view class="login-txt" v-if="timeState == 0" @click="YanZhengMa">发送验证码</view>
					<view class="login-txt" v-if="timeState == 1">{{time}}</view>
				</view>


				<!-- <view class="login-box-s">
					<view class="login-box-s-img" v-if="iconType == 0" @click="iconClick">
						<image src="/static/qq1.png" mode=""></image>
					</view>
					<view class="login-box-s-img" v-if="iconType == 1" @click="iconClick1">
						<image src="/static/qq2.png" mode=""></image>
					</view>
					<view class="login-box-s-txt">
						我认真阅读
						<span @click="ShouCe">用户手册</span>
						和
						<span @click="ZhengCe">隐私政策</span>
					</view>
				</view> -->

				<view class="login-box-btn1" @click="Login">
					立即注册/登录
				</view>
				<view style="height: 48rpx;"></view>
			</view>
		</view>


	</view>
</template>
<script>
	export default {
		components: {},
		data() {
			return {
				windowHeight: "200px",
				msg: '发送验证码',
				iconType: 1,
				btnType: 1, //登录按钮颜色状态

				iponeType: 0, //验证码颜色状态

				iponeCode: 0, //登录提示
				codeCode: 0, //验证码提示
				time: 59,
				timeState: 0,
				ipone: '',
				userSelector: {
					users: [],
					visible: false,
					selectedUser: null
				},
				username: '',
				password: {
					visible: false,
					value: '123'
				},
				InFo: {},
				access_token: '',

				mapping: '1410063740', //物联网卡卡号
				mobile: '', //手机号
				deviceId: '', //手机唯一ID
				code: '', //验证码
				accessToken: '', //token
			}
		},
		onLoad(e) {
			this.GaoDu() //判断手机高度
			console.log(e, '2')
			// this.mapping = e.mapping

		},
		onShow() {
			// 获取手机型号
			let that = this
			uni.getSystemInfo({
				success: function(res) {
					console.log(res, ']手机型号')
					that.deviceId = res.appId
				}
			});


		},
		methods: {
			YanZhengMa() {
				let that = this
				
				this.sendSmsCodeIot()
			},
			TimeS() {
				this.timer = setInterval(() => {
					if (this.time != 0) {
						this.time = this.time - 1
					} else {
						clearInterval(this.timer)
						this.timeState = 0
						this.time = 59
					}
				}, 1000)
			},

			// 获取验证码
			sendSmsCodeIot() {
				let that = this
				uni.request({
					url: this.$api.sendSmsCodeIot, //仅为示例，并非真实接口地址。
					data: {
						mapping: this.mapping,
						mobile: this.mobile,
						deviceId: this.deviceId,
						scene: 1,
					},
					method: 'POST',
					header: {
						['tenant-id']: `${'1'}`
					},
					success: (res) => {
						if(res.data.code == 200){
							uni.showToast({
								duration: 1000,
								title:'发送成功',
								icon: 'none',
							})
							this.timeState = 1
							that.TimeS()
							console.log(res.data);
							this.access_token = res.data.data.access_token
							uni.setStorage({
								key: 'token',
								data: this.access_token,
								success: function() {
									console.log('success');
								}
							});
							setTimeout(() => {
								this.UserInfo(res.data.data.access_token) //用户信息
							}, 1000)
						}else{
							uni.showToast({
								duration: 1000,
								title:res.data.msg,
								icon: 'none',
							})
						}
						
					}
				});
			},





			// 登录
			Login() {
				// if (this.iconType == 1) {
				// 	uni.showToast({
				// 		title: '请勾选协议',
				// 		icon: 'none',
				// 		duration: 1000
				// 	});
				// 	return
				// }
				
				if (this.code == '') {
					uni.showToast({
						title: '验证码不能为空',
						icon: 'none',
						duration: 1000
					});
					return
				}
				// this.$REQ(this.$api.smsLogin, {
				// 	mobile:this.mobile,
				// 	code:this.code
				// }, 'POST').then(res => {
				// 	console.log(res)
				// 	this.accessToken = res.data.data.accessToken

				// 	uni.setStorage({
				// 		key: 'accessToken',
				// 		data: res.data.data.accessToken,
				// 		success: function () {
				// 			console.log('success');
				// 		}
				// 	});
				// }).catch(err => {
				// 	console.log(err)
				// 	uni.showToast({
				// 		duration: 1000,
				// 		title:err.data.msg,
				// 		icon: 'none',
				// 	})
				// })
				uni.request({
					url: this.$api.loginIot, //仅为示例，并非真实接口地址。
					data: {
						mobile: this.mobile,
						deviceId: this.deviceId,
						code: this.code
					},
					method: 'POST',
					header: {
						['tenant-id']: `${'1'}`
					},
					success: (res) => {
						console.log(res.data);
						this.access_token = res.data.data.access_token
						
						uni.setStorage({
							key: 'info',
							data: res.data.data,
							success: function() {
								console.log('success');
							}
						});
						let iponeInfo = {
							deviceNo: this.deviceNo,
							deviceId: this.deviceId
						}
						uni.setStorage({
							key: 'iponeInfo',
							data: iponeInfo,
							success: function() {
								console.log('success');
							}
						});
						uni.reLaunch({
							url: '/pages/index/index'
						});
						setTimeout(() => {
							this.UserInfo(res.data.data.access_token) //用户信息
						}, 1000)
					}
				});
				
			},
			iconClick() {
				this.iconType = 1
			},
			iconClick1() {
				this.iconType = 0
			},
			// 判断手机高度
			GaoDu() {
				// 判断手机页面的高度
				uni.getSystemInfo({
					success: (res) => {
						this.windowHeight = res.windowHeight + "px";
					}
				})
			},
		}
	}
</script>

<style scoped lang="less">
	.login {
		width: 100%;
		height: 100%;
	}

	.login-box {
		width: 686rpx;
		background: #FFFFFF;
		border-radius: 16rpx;
		margin: auto;
	}

	.login-box-one {
		width: 330rpx;
		height: 40rpx;
		font-family: HarmonyOS_Sans_SC_Bold;
		font-size: 48rpx;
		color: #23292C;
		line-height: 40rpx;
		text-align: left;
		font-style: normal;
		padding-top: 64rpx;
		margin-left: 32rpx;
		padding-bottom: 48rpx;
		font-weight: 600;
	}

	.login-box-ipone {
		width: 622rpx;
		height: 112rpx;
		background: #F3F3F3;
		border-radius: 20rpx;
		margin: auto;
	}

	.login-box-ipone input {
		padding-left: 32rpx;
		padding-top: 32rpx;
	}

	.login-box-ipone1 {
		display: flex;
		flex-wrap: nowrap;
		justify-content: space-between;
		width: 622rpx;
		height: 112rpx;
		background: #F3F3F3;
		border-radius: 20rpx;
		margin: auto;
	}

	.login-code {
		padding-left: 32rpx;
		padding-top: 32rpx;
	}

	.login-txt {
		width: 170rpx;
		height: 36rpx;
		font-family: HarmonyOS_Sans_SC;
		font-size: 32rpx;
		color: #18A8F7;
		line-height: 40rpx;
		text-align: left;
		font-style: normal;
		padding-top: 32rpx;
		padding-right: 32rpx;
	}

	.login-txt1 {
		width: 170rpx;
		height: 36rpx;
		font-family: HarmonyOS_Sans_SC;
		font-size: 32rpx;
		color: #00A5FF;
		line-height: 40rpx;
		text-align: left;
		font-style: normal;
		padding-top: 32rpx;
		padding-right: 32rpx;
	}

	.login-box-s {
		padding-left: 32rpx;
		padding-top: 16rpx;
		display: flex;
		padding-bottom: 32rpx;
	}

	.login-box-s-img {
		width: 32rpx;
		height: 32rpx;
		padding-top: 3rpx;
	}

	.login-box-s-img image {
		width: 100%;
		height: 100%;
	}

	.login-box-s-txt {
		font-family: HarmonyOS_Sans_SC;
		font-size: 28rpx;
		color: #666666;
		line-height: 39rpx;
		text-align: left;
		font-style: normal;
		padding-left: 10rpx;
	}

	.login-box-s-txt span {
		font-family: HarmonyOS_Sans_SC;
		font-size: 28rpx;
		color: #00A5FF;
		line-height: 39rpx;
		text-align: left;
		font-style: normal;
	}

	.login-box-btn {
		width: 622rpx;
		height: 112rpx;
		background: #A9DEFA;
		border-radius: 20rpx;
		margin: auto;
		font-family: HarmonyOS_Sans_SC;
		font-size: 32rpx;
		color: #FFFFFF;
		line-height: 40rpx;
		text-align: right;
		font-style: normal;
		text-align: center;
		line-height: 112rpx;
	}

	.login-box-btn1 {
		width: 622rpx;
		height: 112rpx;
		background: #18A8F7;
		border-radius: 20rpx;
		margin: auto;
		font-family: HarmonyOS_Sans_SC;
		font-size: 32rpx;
		color: #FFFFFF;
		line-height: 40rpx;
		text-align: right;
		font-style: normal;
		text-align: center;
		line-height: 112rpx;
		margin-top: 32rpx;
	}

	.ipone-prompt {
		font-family: HarmonyOS_Sans_SC;
		font-size: 28rpx;
		color: #ED0000;
		line-height: 39rpx;
		text-align: left;
		font-style: normal;
		padding-left: 64rpx;
		padding-top: 16rpx;
	}
</style>